package com.votesys.model;

import java.sql.Timestamp;
import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

/**
 * A data access object (DAO) providing persistence and search support for
 * Votecontent entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.votesys.model.Votecontent
 * @author MyEclipse Persistence Tools
 */
public class VotecontentDAO extends HibernateDaoSupport {
	private static final Logger log = LoggerFactory
			.getLogger(VotecontentDAO.class);
	// property constants
	public static final String TOPIC_ID = "topicId";
	public static final String CONTENT_NAME = "contentName";
	public static final String CONTENT_ABSTRACT = "contentAbstract";
	public static final String CONTENT_DETAIL = "contentDetail";
	public static final String PIC = "pic";
	public static final String CONTENT_COUNT = "contentCount";

	protected void initDao() {
		// do nothing
	}

	public void save(Votecontent transientInstance) {
		log.debug("saving Votecontent instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(Votecontent persistentInstance) {
		log.debug("deleting Votecontent instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public Votecontent findById(java.lang.Integer id) {
		log.debug("getting Votecontent instance with id: " + id);
		try {
			Votecontent instance = (Votecontent) getHibernateTemplate().get(
					"com.votesys.model.Votecontent", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(Votecontent instance) {
		log.debug("finding Votecontent instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Votecontent instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from Votecontent as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTopicId(Object topicId) {
		return findByProperty(TOPIC_ID, topicId);
	}

	public List findByContentName(Object contentName) {
		return findByProperty(CONTENT_NAME, contentName);
	}

	public List findByContentAbstract(Object contentAbstract) {
		return findByProperty(CONTENT_ABSTRACT, contentAbstract);
	}

	public List findByContentDetail(Object contentDetail) {
		return findByProperty(CONTENT_DETAIL, contentDetail);
	}

	public List findByPic(Object pic) {
		return findByProperty(PIC, pic);
	}

	public List findByContentCount(Object contentCount) {
		return findByProperty(CONTENT_COUNT, contentCount);
	}

	public List findAll() {
		log.debug("finding all Votecontent instances");
		try {
			String queryString = "from Votecontent";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public Votecontent merge(Votecontent detachedInstance) {
		log.debug("merging Votecontent instance");
		try {
			Votecontent result = (Votecontent) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(Votecontent instance) {
		log.debug("attaching dirty Votecontent instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(Votecontent instance) {
		log.debug("attaching clean Votecontent instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static VotecontentDAO getFromApplicationContext(
			ApplicationContext ctx) {
		return (VotecontentDAO) ctx.getBean("VotecontentDAO");
	}
}